# _*_ coding:utf-8 _*_
# @Time  : 2023.04.24
# @Author: zizlee
import time

import pandas as pd
import requests
from urllib3 import disable_warnings
disable_warnings()

def read_file():
    df = pd.read_excel('瑞智系统营业部用户.xlsx', engine='openpyxl')
    df.rename(columns={
        '营业部': 'department',
        '用户': 'account',
        '密码': 'password'
    }, inplace=True)
    return df

def add_account():


    df = read_file()
    # url = 'http://127.0.0.1:8000/v1/ruizy/user/'  # POST
    url = 'https://210.13.218.130:9000/v1/ruizy/user/'  # POST

    for row in df.to_dict(orient='records'):
        user_data = {
            'nickname': row['department'],
            'admin_name': row['department'],
            'password': row['password'],
            'expire': '2099/12/31',
            'role_code': 2000,
            'out_role': 248,
            'ruizy_code': row['account']
        }
        try:
            r = requests.post(url, json=user_data, verify=False)
        except Exception as e:
            print('添加失败', str(e))
        else:
            print(r.json(), row)

        time.sleep(1)


def add_quota():
    t = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjIsInJvbGVfY29kZSI6OTk5OSwib3V0X3JvbGUiOjI1NSwiZXhwIjoxNjgyNjU4NDYxLjg1Nzk1M30.7mrvh_Mv86yh_lwn21BkTor_wcTSW6KDWrGm4rZQf98'
    url = 'https://210.13.218.130:9000/v1/ruizy/userListInfo/?role=248&active=0&export_flag=0'  # GET
    r = requests.get(url, headers={'Ruizy-Token': t}, verify=False)
    res = r.json()
    coin_url = 'https://210.13.218.130:9000/v1/prse/quota/change/'
    for user in res['data']:
        body = {
            'new_quota': 100000,
            'action': 'add',
            'uid': user['id']
        }
        r = requests.post(coin_url, headers={'Ruizy-Token': t}, json=body, verify=False)
        print(user['id'], user['admin_name'], r.json())
        time.sleep(1)


# add_quota()

class A:
    def a_func(self):
        print('this is func a')


attr = getattr(A(), 'a_func', None)
if attr:
    attr()
print(attr)

